<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup" lvKeepRequiredWidth>
    <lv-form-item>
        <lv-form-label>
            {{'protection_restore_to_label' | i18n}}
        </lv-form-label>
        <lv-form-control>
            <lv-radio-group formControlName="restoreLocation">
                <lv-group [lvGutter]="'24px'">
                    <lv-radio [lvValue]="restoreLocationType.ORIGIN" [lvDisabled]="disabledOrigin" [lv-tooltip]="rowCopy?.resource_status === 'NOT_EXIST' ?
                        ('protection_cloud_origin_restore_disabled_label' | i18n) :
                        restoreToNewLocationOnly ?
                        ('protection_origin_restore_disabled_label'| i18n) :
                        ''">
                        {{ 'common_restore_to_origin_location_label' | i18n }}
                    </lv-radio>
                    <lv-radio [lvValue]="restoreLocationType.NEW">
                        {{'common_restore_to_new_location_label' | i18n}}
                    </lv-radio>
                </lv-group>
            </lv-radio-group>
        </lv-form-control>
    </lv-form-item>
    <ng-container *ngIf="formGroup.value.restoreLocation === restoreLocationType.ORIGIN">
        <lv-form-item>
            <lv-form-label>
                {{'common_target_compute_position_label' | i18n}}
            </lv-form-label>
            <lv-form-control>
                <input lv-input type="text" formControlName="originPosition" />
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <ng-container *ngIf="formGroup.value.restoreLocation === restoreLocationType.NEW">
        <lv-form-item>
            <lv-form-label lvRequired>
                {{ 'common_target_compute_position_label' | i18n }}
                <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_computer_location_help_label' | i18n}}"
                    lvTooltipPosition="rightTop" lvTooltipTheme="light" class="configform-constraint"
                    lvColorState='true'></i>
            </lv-form-label>
            <lv-form-control>
                <lv-group lvDirection="vertical" lvGutter="20px">
                    <lv-select formControlName="environment" [lvOptions]="environmentOptions" lvValueKey="value"
                        lvShowFilter lvFilterKey="label" lvFilterMode="contains"
                        lvPlaceholder="{{'common_select_virtual_environment_label'|i18n}}">
                    </lv-select>
                </lv-group>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label></lv-form-label>
            <lv-form-control>
                <lv-tree-select [lvTreeData]="treeData" lvTreeSelectionMode="single" formControlName="host" lvShowClear
                    lvTreeShowContentIcon lvPlaceholder="{{'common_select_vm_label'|i18n}}" lvVirtualScroll
                    (lvExpandedChange)="expandedChange($event)">
                </lv-tree-select>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label lvRequired>{{'protection_storage_location_label' | i18n}}
                <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_storage_location_help_label' | i18n}}"
                    lvTooltipPosition="rightTop" lvTooltipTheme="light" class="configform-constraint"
                    lvColorState='true'></i>
            </lv-form-label>
            <lv-form-control>
                <lv-radio-group formControlName="storage">
                    <lv-group [lvGutter]="'30px'">
                        <lv-radio [lvValue]="DatastoreType.SAME">{{'protection_same_database_label' | i18n}}
                        </lv-radio>
                        <lv-radio [lvValue]="DatastoreType.DIFFERENT">{{'protection_diff_database_label' | i18n}}
                        </lv-radio>
                    </lv-group>
                </lv-radio-group>
            </lv-form-control>
        </lv-form-item>
        <ng-container *ngIf="formGroup.value.storage === DatastoreType.SAME">
            <lv-form-item>
                <lv-form-label lvRequired>
                    {{ 'common_datastore_label' | i18n }}
                </lv-form-label>
                <lv-form-control>
                    <lv-select formControlName="dataStore" [lvOptions]="dataStoreOptions" lvValueKey="value"
                        lvShowFilter lvFilterKey="label" lvFilterMode="contains">
                    </lv-select>
                </lv-form-control>
            </lv-form-item>
        </ng-container>
    </ng-container>
</lv-form>

<div class="aui-gutter-column-xl"></div>
<lv-collapse [lvMultiExpansion]="'false'" lvType="simple">
    <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="false">
        <lv-form [formGroup]="formGroup" [lvLabelColon]="false" class="formGroup">
            <lv-form-item>
                <lv-form-label>
                    {{'protection_proxy_host_label' | i18n}}
                </lv-form-label>
                <lv-form-control>
                    <lv-select [lvOptions]="proxyOptions" formControlName="proxyHost" lvValueKey='value' lvShowCheckAll
                        lvShowFilter lvFilterKey="label" lvFilterMode="contains" lvMode="multiple"
                        lvPlaceholder="{{'protection_agent_placeholder_label' | i18n}}">
                    </lv-select>
                </lv-form-control>
            </lv-form-item>
            <lv-form-item class="auto-power-switch-item">
                <lv-form-label>
                    <div [ngClass]="{'auto-power-switch-en-us': isEn, 'auto-power-switch-zh-cn': !isEn}" lv-overflow>
                        {{'protection_auto_power_on_label' | i18n}}
                    </div>
                </lv-form-label>
                <lv-form-control>
                    <lv-switch formControlName="power_on"></lv-switch>
                </lv-form-control>
            </lv-form-item>
            <lv-form-item>
                <lv-form-label>{{'common_restore_before_copy_verify_label' | i18n}}
                    <i lv-icon="aui-icon-help" lv-tooltip="{{'protect_hcs_restore_before_copy_verify_label' | i18n}}"
                        lvTooltipPosition="rightTop" lvTooltipTheme="light" class="configform-constraint"
                        lvColorState='true'></i>
                </lv-form-label>
                <lv-form-control>
                    <lv-switch formControlName="copyVerify"
                        [lv-tooltip]="verifyStatus === CopyDataVerifyStatus.noGenerate.value ? copyVerifyDisableLabel : ''"
                        [lvDisabled]="verifyStatus === CopyDataVerifyStatus.noGenerate.value">
                    </lv-switch>
                </lv-form-control>
            </lv-form-item>
        </lv-form>
    </lv-collapse-panel>
</lv-collapse>
<ng-template #titleTpl>
    <lv-group lvGutter='8px'>
        <span class="aui-h3">{{'common_advanced_label'|i18n}}</span>
    </lv-group>
</ng-template>